package com.tailyou.hms.firstapp.act;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.tailyou.hms.firstapp.R;
import com.tailyou.hms.firstapp.adapter.WelcomeAdapter;

import java.util.ArrayList;
import java.util.List;

import me.relex.circleindicator.CircleIndicator;

public class WelcomeActivity extends AppCompatActivity {

    private ViewPager vpWelcome;
    private CircleIndicator indicator;
    private Button btnStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        // 获取控件
        vpWelcome = findViewById(R.id.vpWelcome);
        indicator = findViewById(R.id.indicator);
        btnStart = findViewById(R.id.btnStart);

        // 准备数据
        List<Integer> data = new ArrayList<>();
        data.add(R.mipmap.welcome1);
        data.add(R.mipmap.welcome2);
        data.add(R.mipmap.welcome3);
        data.add(R.mipmap.welcome4);
        data.add(R.mipmap.welcome5);

        // 设置适配器
        vpWelcome.setAdapter(new WelcomeAdapter(this, data));
        indicator.setViewPager(vpWelcome);

        // 添加切换监听
        vpWelcome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                btnStart.setVisibility(position == 4 ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

}